package com.app.studyroom.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.app.studyroom.R;
import com.app.studyroom.model.LayoutElement;

import java.util.List;

public class RowAdapter extends RecyclerView.Adapter<RowAdapter.RowHolder> {

    private final List<List<LayoutElement>> layoutRows;
    private final boolean enableReservation;

    public RowAdapter(List<List<LayoutElement>> layoutRows, boolean enableReservation) {
        this.layoutRows = layoutRows;
        this.enableReservation = enableReservation;
    }

    @NonNull
    @Override
    public RowHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.seat_row, parent, false);
        return new RowHolder(view);
    }

    @Override
    public void onBindViewHolder(@NonNull RowHolder holder, int position) {
        List<LayoutElement> row = layoutRows.get(position);
        ClassLayoutElementAdapter adapter = new ClassLayoutElementAdapter(
                holder.recyclerView.getContext(), row, enableReservation);
        holder.recyclerView.setLayoutManager(new LinearLayoutManager(holder.recyclerView.getContext(), RecyclerView.HORIZONTAL, false));
        holder.recyclerView.setAdapter(adapter);
    }

    @Override
    public int getItemCount() {
        return layoutRows.size();
    }

    static class RowHolder extends RecyclerView.ViewHolder {
        RecyclerView recyclerView;

        public RowHolder(@NonNull View itemView) {
            super(itemView);
            recyclerView = itemView.findViewById(R.id.seats_recycler_view);
        }
    }
}
